<?php

class YimeDevTools
{
    public static function checkSiteStatus()
    {
        if (!self::checkSiteIsInstalled())
            redirect('install');

        self::updateDb();
        self::loadTestData();
    }

    public static function checkSiteIsInstalled()
    {
        /** @var CI $CI */
        $CI =& get_instance();

        //判断是否已安装
        if ($CI->db->table_exists('option') && Option_Model::getOption('installed')) {
            return true;
        }

        return false;
    }

    public static function checkDbUpdate()
    {

    }

    public static function updateDb()
    {
        /** @var CI $CI */
        $CI =& get_instance();
        $CI->load->library('migration');
        if (!$CI->migration->current()) {
            show_error($CI->migration->error_string());
        }
    }

    public static function loadTestData()
    {
        //测试用户
        if (ENVIRONMENT != 'development')return;
        try{
            $thatUser = UserManager::register('admin@hiyime.com', '123123');
            $thatUser->setPower(99999);
            User_Model::update($thatUser);
            UserManager::register('1@hiyime.com', '123123');
            UserManager::register('2@hiyime.com', '123123');
        }catch (Exception $e){

        }

    }

} 